/**
 * @Author :sunwei
 * @Description:
 * @Date create in 18:55  2021/5/23
 * @Modified by:
 */
public class ThreadFlagClose implements Runnable {

    private volatile boolean flag = false;
    public void start(){
        Thread thread = new Thread(this,"Thread-close-test1");
        thread.start();
    }
    @Override
    public void run() {
        while(!flag){
            System.out.println("do some things !!");
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("force shutdown!!");
    }

    public void stop(){
        if(!flag){
            flag=!flag;
        }
    }
}
